<?php

/**
 * @author christian
 * @copyright 2011
 */

Class CTourEditDraw
{
   
    
    public static $instance;
    
    function __construct()
    {
      
        
    }
    function  DrawHead($action,$name,$method,$NAME){echo "<div id='register-box'>\n";echo "<form action='$action' method='$method' name='$name'>\n";echo "<h2>$NAME</h2>\n";}
    function  DrawFoot(){
        echo "</form>";
        echo "</div>";}
        
        
    function DrawSection($name){
            echo "<h2> $name</h2>";
    }
        
    function  DrawTextFillBox($title,$items, $maintable, $mainfield, $id, $val)
    {
            
        ?>
               <p>
               <?php 
           
            
    echo "<h3> $title</h3>";

           
               
        $query="select ";
        foreach($items as $campo => $valor){$query=$query.$campo." ,";}
        $query= substr($query,0,strlen($query)-1);
        $query=$query." from " .$maintable. " where $mainfield=". $id;

        $table3=CModelo::getInstance()->getData($query);
     
       
        foreach($table3 as $row =>$colum)
        {
        $tablek=$colum;$k=0;$j=0;$i=0;
        foreach($tablek as $campo=>$valor)
        {
           foreach($items as $field => $name){
                $items_table[$k]=$name;   
                $k=$k+1;
        }
        
          
            
            $select="<label>". $items_table[$j] . "</br>";
            $select = $select."<input type='text' id='$campo' name='$campo' class='$val[$i]' value='".$tablek[$campo]."'>";
            echo $select."</label></br>";
            $j=$j+1;
            $i=$i+1;
        }     
        }          
               ?>
               
               </p> 
            
        <?php
        
    }
    
    
    function DateFromTo($title,$boundary, $idPackTour){
        
    ?>        
    <script>
    $(function() {

 
       $.datepicker.setDefaults($.datepicker.regional['es']); 
    
    });
    
	$(function() {
	   
 
  		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "+1d",
			changeMonth: false,
			numberOfMonths: 3,
			onSelect: function( selectedDate ) {
			    
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		
        });
        
        
	});
    
    $query = "select DateBegTour, "
	</script>
    <label> <?php echo $title?> </label><br/><br/>  
    <label for="from"><?php echo $boundary[0]?></label>
    <input type="text" class=":required"  id="from" name="from" /></br>
    <label for="from"><?php echo $boundary[1]?></label>
    <input type="text" class=":required" id="to" name="to"/>

    <?php
       
   
    
    }
    
    
    
     function getDefaultTour($maintable,$mainfield,$mainid,$subfield){
        
        $query="select ". $subfield ." from ". $maintable . " where $mainfield='$mainid' AND DefaultTourPack=1";
//echo $query;
        $table=CModelo::getInstance()->getData($query);
        
        $identificador="";
         foreach($table as $fila=>$columna){
            $tabla1=$columna;
                foreach($tabla1 as $field=>$value)
                {
                $identificador=$value;
            }
         }
         return $identificador;
     
    }
    
    function HiddenValue($value, $name){
        echo "<input type='hidden' name='$name' value='$value'>"; 
    }
    
    function DrawButton($nombre,$url){
//        echo "<form action='Cbienvenida.php' method='post'> <input type='button' name='BYLAWS' value='BYLAWS'></form>";
 //      echo "<form action='http://www.the-packrat.com/bylaws.html' method='post'> <input type='link' name='BYLAWS' value='BYLAWS' target='framename'></form>";
        //echo "<form action='http://www.the-packrat.com/bylaws.html' method='get' target='framename'><input type='button' value='BYLAWS'></form>";
        

        echo "<input type=button onClick=\"parent.location='$url'\" value='$nombre'><br/>";
}
        
    function DrawAreaFill($label,$table,$field,$id){

    $query = "SELECT $field[1] from $table where $field[0]='$id'";
    
    $result = CModelo::getInstance()->getData($query);
    
        foreach($result as $r => $c){
            $table = $c;
            foreach($table as $r1 => $c1){
                $comments = $c1;
            }
        }
        
        echo "</br><label>$label</label><br><textarea cols='41' name='$field[1]' rows='5' wrap='ON'> $comments </textarea></br>";
    }
            
    function getAnyId($maintable,$mainfield,$mainid,$subfield){
        
        $query="select ". $subfield ." from ". $maintable . " where $mainfield= $mainid";
        //echo $query;
        $table=CModelo::getInstance()->getData($query);
        
        $identificador="";
         foreach($table as $fila=>$columna){
            $tabla1=$columna;
                foreach($tabla1 as $field=>$value)
                {
                $identificador=$value;
            }
         }
         return $identificador;
     
    }
    
    
    function DrawMultiple($table,$campos,$NAME)//especificar los campos que deben de aparecer 
    {
        
      $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;      

        $table2=CModelo::getInstance()->getData($query);
        

        ?>
        
        <select style="width: 400px;" name="multi[]" multiple="multiple" class="input_pulldown" ><option value="all">Búsqueda Global</option>
       <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo]. " ";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select>       
        </label></br>
        
    
    <?php
    }    
    
    function DrawMultipleFilter($table,$campos,$NAME,$filter,$id)//especificar los campos que deben de aparecer 
    {
        
        
        $query="SELECT  `actividades_has_tour_has_pasajero`.`idActPaxTour` ,`actividades`.`NomAct` FROM actividades 
                LEFT JOIN  `viv`.`actividades_has_tour_has_pasajero` ON  `actividades`.`idAct` =  `actividades_has_tour_has_pasajero`.`actividades_idAct` 
                WHERE ((operador_idOpe =$filter))";      
        
        $table2=CModelo::getInstance()->getData($query);
        

        ?>
          <label><?php echo $NAME;?></br>
        <select style="width: 400px;" name="<?php echo $id;?>[]" class=":required" multiple="multiple" id="<?php echo $id;?>"><option value="all"></option>
       <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo]. " ";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select>       
        </label></br>
        
    
    <?php
    }    
      
            
    function DrawMultipleSelect($maintable, $table,$campos,$NAME, $id, $idnomain)//especificar los campos que deben de aparecer 
    {
        
      $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;      

        $table2=CModelo::getInstance()->getData($query);
        
    
       $identificador = 0;
        
       $query2= "select ". $idnomain ." from ".$maintable." where pack_has_tour_idPackTour = $id";
       //echo $query2;
                $table3=CModelo::getInstance()->getData($query2);
               // var_dump($table3);
        $f=0;
        $identificador="";$listado="";
     foreach($table3 as $fila=>$columna)
     {
        $tabla4=$columna;
        foreach($tabla4 as $field=>$value)
        {
            $identificador[]=$value;
        }
        $listado = $listado.$identificador[$f]." ,";$f++;
      
    }
    
        if($identificador!=0){ 
            sort($identificador);}
      $listado= substr($listado,0,strlen($listado)-1);
         
      //  var_dump($identificador);
       $j=0;
       //  foreach($identificador as $c=>$r){
          //      echo $identificador[$j]."/";
         ///       $j++;
          //  }
       
        ?>
        
        <label><?php echo $NAME."</br>";
        echo " <h6>Los paquetes definidos son: $listado </h6>"
        ?>
        
        <select style="width: 400px;" name="multi[]" multiple="multiple" class="input_pulldown" >
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;
        $select="";
        $i=0;
        foreach($tabla as $campo=>$valor)
        {   
            
          
            if($valor==$identificador[$j]){
                $select=$select."<option selected value=".$colum." MULTIPLE> ($valor) ";
                $j++;
            }
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            elseif ($i<=0){$select=$select."<option value=".$valor."> ($valor) ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo];}
            $i=$i+1;
        }
        echo $select."</option>";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select>       
        </label></br>
        
    
    <?php
    }
    
    
    
        
    function DrawSelect($maintable,$table,$campos,$NAME, $id, $idnomain, $size,$num)//especificar los campos que deben de aparecer 
    {        
      $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;      


        $table2=CModelo::getInstance()->getData($query);
 
        $query2= "select ". $idnomain ." from ".$maintable." where pack_has_tour_idPackTour = $id and NumGui=$num";
        //echo $query2; 
        $table3=CModelo::getInstance()->getData($query2);
         
        $identificador="";
         foreach($table3 as $fila=>$columna)
        {
        $tabla4=$columna;
        foreach($tabla4 as $field=>$value)
        {
            $identificador=$value;
            }
        }
        
        if($identificador==""){$identificador="No definido";}
 

        ?>
        
        

        
        <label><?php echo $NAME. " (".$identificador.")";?></br>
        <select style="width:400px" name="idGuide<?php echo $num;?>" class="input_pulldown" size="<?php echo $size;?>"><option></option>
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;
        $select="";
        $i=0;
        foreach($tabla as $campo=>$valor)
        { 
            if($identificador==$valor){
              $select=$select."<option selected value=".$identificador."> (". $valor. ") ";;
                
            }
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            elseif ($i<=0){$select=$select."<option value=".$valor."> (". $valor. ") ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo]." ";}
            $i=$i+1;
        }
        echo $select."</option>";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select></br>       
        </label>
        
    
    <?php
    }
    function DrawRadioButton($items,$name)
    {
      
      echo "<p >";
      
      foreach($items as $id => $valor)
                    {
                        echo "<label>".$id."<input type='radio' class=\"input-radio\" name='$name' value='$valor'>"."</label>\n";
                        
                    }
      
      
      echo "</p>";
      
        
        
    }
    
    
    function DrawSubmmit($nombre){
        
        
        echo "<p align='right'><input class='submit_button' type='submit' name=$nombre value='$nombre'></p>";
        
        
        }
    
    public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new CTourEditDraw();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	
    
    
}

?>